﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RedHouse.Data.Entities;
using RedHouse.Data.Common;
using RedHouse.Data.Base;

namespace RedHouse.AdminControl
{
    public partial class Login : System.Web.UI.Page
    {
        public string Message { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            btnLogin.Click += new EventHandler(btnLogin_Click);
            Message = string.Empty;

        }

        void btnLogin_Click(object sender, EventArgs e)
        {
            RedHouseUserAccount account = GetAccountInfo();
            OperationResult loginResult = UserAccountService.Instance.Login(account);
            if (loginResult.Result)
            {
                Session["Account"] = loginResult.ReturnObject;
                Response.Redirect("Default.aspx");
            }
            else
            {
                Message = "Login failed!";
            }
        }

        private RedHouseUserAccount GetAccountInfo()
        {
            RedHouseUserAccount account = new RedHouseUserAccount()
            {
                UserId = txtUserName.Text,
                Password = txtPassword.Text
            };

            return account;
        }
    }
}